import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { LoginData, LoginResult, CaptchaResult } from './model';

class AuthAPI {
    /**
     * 登录API
     * 
     * @param data 登录数据
     * @returns 登录结果
     */
    static login(data: LoginData): AxiosPromise<LoginResult> {
        const formData = new FormData();
        formData.append('username', data.username);
        formData.append('password', data.password);
        formData.append('captchaKey', data.captchaKey || "");
        formData.append('captchaCode', data.captchaCode || "");
        return request({
            url: '/api/v1/auth/login',
            method: 'post',
            data: formData,
            headers: {
                'Content-Type': 'multipart/form-data'
            }
        })
    }

    /**
     * 注销API
     */
    static logout(): AxiosPromise<any> {
        return request({
            url: '/api/v1/auth/logout',
            method: 'delete'
        })
    }

    /**
     * 获取验证码API
     */
    static getCaptcha() {
        return request<any, CaptchaResult>({
            url: '/api/v1/auth/captcha',
            method: 'get'
        })
    }
}

export default AuthAPI;
// /**
//  * 登录API
//  * 
//  * @param data 登录数据
//  * @returns 登录结果
//  */
 
//  export function AuthAPI(data: LoginData): AxiosPromise<LoginResult> {
//      return request({
//         url: '/api/v1/auth/login',
//         method: 'post',
//         params: data
//      })
//  }